# coding: utf8
# datetime: 2021-04-06
# 题目地址: https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/

from typing import List

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        len_num = len(nums)
        if len_num < 2:
            return len_num
        ret = len_num
        tmp = nums[-1]
        len_num = len_num-2
        count = 1
        while len_num>=0:
            if tmp == nums[len_num]:
                if count == 2:
                    nums.pop(len_num)
                    ret -= 1
                else:
                    count += 1
            else:
                tmp = nums[len_num]
                count = 1
            len_num -= 1
        return ret

nums = [0,0,1,1,1,1,2,3,3]
a = Solution()
print(a.removeDuplicates(nums))
print(nums)